/*
 * @Author: 张家亮 1690608011@qq.com
 * @Date: 2022-08-17 17:30:22
 * @LastEditors: 张家亮 1690608011@qq.com
 * @LastEditTime: 2022-08-28 14:09:50
 * @FilePath: \vue-store-server\app\models\dao\userDao.js
 * @Description: 用户模块数据持久层
 * 
 * Copyright (c) 2022 by 张家亮 1690608011@qq.com, All Rights Reserved. 
 */
const db = require('./db.js');

module.exports = {
  // 连接数据库根据用户名和密码查询用户信息
  Login: async (userName, password) => {
    const sql = 'select * from users where userName = ? and password = ?';
    return await db.query(sql, [userName, password]);
  },
  // 连接数据库根据用户名查询用户信息
  FinUserByName: async (userName) => {
    const sql = 'select * from users where userName = ?';
    return await db.query(sql, [userName]);
  },
  // 连接数据库根据用户id查询用户信息
  FindUserByUser_id: async (user_id) => {
    const sql = 'select * from users where user_id = ?';
    return await db.query(sql, [user_id]);
  },
  // 连接数据库根据用户id和密码查询用户信息
  FindUserByPassAndUser_id: async (user_id, password) => {
    const sql = 'select * from users where user_id = ? and password = ?';
    return await db.query(sql, [user_id, password]);
  },
  UpdateUserInfo: async (user) => {
    const sql = 'update users set userPhoneNumber = ?,age = ?,sex = ?,personal_sign = ? where user_id = ? ';
    return await db.query(sql, [user.userPhoneNumber, user.age, user.sex, user.personal_sign, user.user_id]);
  },
  UpdatePassword: async (password, user_id) => {
    const sql = 'update users set password = ? where user_id = ? ';
    return await db.query(sql, [password, user_id]);
  },
  // 连接数据库插入用户信息
  Register: async (userName, password) => {
    const sql = 'insert into users values(null,?,?,null,null,null,null)';
    return await db.query(sql, [userName, password]);
  }
}